package com.ww.springboot.boot.test;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
 
public class HiveUtil {
	public static void main(String[] args) {
		String connectionURL = "jdbc:hive2://5.2.25.25:10000/hai";
		String drivername = "org.apache.hive.jdbc.HiveDriver";
		String username = "";
		String password = "";
		try {
			Class.forName(drivername);
		} catch (ClassNotFoundException e) {
			e.printStackTrace();
			System.exit(1);
		}
		try {
			Connection con = DriverManager.getConnection(connectionURL, username, password);
			if (con != null) {
				System.out.println("Connected");
			} else {
				System.out.println("Not Connected");
			}
			Statement stmt = con.createStatement();
			String sql;
			ResultSet res;
			sql = "select * from v_zdry_idx_jxxx  limit 10";
			System.out.println("Running: " + sql);
			res = stmt.executeQuery(sql);
			
			while (res.next()) {
				System.out.println(String.valueOf(res.getString(1)) + "\t" + res.getString(2));
			}
		} catch (SQLException se) {
			se.printStackTrace();
		}
 
	}
}